import dynamic from 'dva/dynamic';
const modelNotExisted = (app, model) =>
  !app._models.some(({ namespace }) => {
    return namespace === model.substring(model.lastIndexOf('/') + 1);
  });

export const dynamicWrapper = ({ models=[], component, ...dynamics } : { models?: Array<string>, component: any }) =>
  dynamic({
    // @ts-ignore
    app: window.dvaApp,
    models: () =>
      models.filter(model => modelNotExisted(window.dvaApp, model)).map(model => modelNotExisted(window.dvaApp, model)).map(m => import(`@/models/${m}`)),
    component,
    ...dynamics
  }) as any;
